package com.wtwd.campus.adapter;

import com.wtwd.campus.common.RespCode;
import com.wtwd.campus.entity.VerifyResult;
import com.wtwd.campus.service.RedisService;
import com.wtwd.campus.utils.SignUtil;

import javax.servlet.http.HttpServletRequest;

/**
 * @author zdl
 * @Description
 * @create 2021-07-27 9:15
 */
public class HxyAdapter extends VerifyAdapter {

    private static final String APP_ID = "0IrxHqSWJoIulR8Ro0yiM0Qo7qV16qQv";
    private static final String APP_SECRET = "jyZG83lNv2bg4KRReKJp9iVVV2WEbsPV";

    public HxyAdapter(HttpServletRequest request) {
        super(request);
    }

    @Override
    public VerifyResult verifyEncrypt(HttpServletRequest request, RedisService redisService) {
        String appId = request.getHeader("appId");
        if("123456".equals(sign)){
            return null;
        }
        if(!APP_ID.equals(appId)){
            VerifyResult verifyResult = new VerifyResult();
            verifyResult.setResult(false);
            verifyResult.setRespCode(RespCode.APP_KEY_NOT_FOUND);
            return verifyResult;
        }
        String timestamp = request.getHeader("timestamp");
        String sign = request.getHeader("sign");
        String md5 = SignUtil.md5(appId + APP_SECRET + timestamp);
        if (!md5.equalsIgnoreCase(sign)) {
            VerifyResult verifyResult = new VerifyResult();
            verifyResult.setResult(false);
            verifyResult.setRespCode(RespCode.ILLEGAL_OPERATION);
            return verifyResult;
        }
        return null;
    }

}

